<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="hibernate.constraint.Constraint" %>
<%@ page import="javax.servlet.http.HttpSession" %>
<%@ page import="java.io.PrintWriter" %>

<%@page import="hibernate.constraint.Constraint"%>
		    <%@ page import="org.hibernate.SessionFactory" %>
    <%@ page import="org.hibernate.Session" %>
    <%@ page import="java.util.List" %>
    <%@ page import="hibernate.model.*"  %>
    <%@ page import="hibernate.util.HibernateUtil" %>
    <%@ page import="hibernate.method.*" %>
	<%
        SessionFactory sessionFactory = HibernateUtil.getSessionAnnotationFactory();
	Session s = sessionFactory.openSession();
s.beginTransaction();
 UserMethods user_m = new UserMethods(); %>
 
<form name="Login" action="Login" method="POST">
<div id="logintxtblank">
	<div id="loginheading">
		
	<%
	//response.setContentType("text/html");
	//String fail = (String) session.getAttribute(Constraint.SESSION_FAILURE);
	//String success = (String) session.getAttribute(Constraint.SESSION_SUCCESS);
	//if(fail != null)out.println("fail" + fail);
	//else if(success !=null) out.println("successs" + success); 
	%>
	
	
	<% Integer user_id = (Integer) session.getAttribute("user_id");
			response.setContentType("text/html");
			if (user_id != null) {%>
				<h5>Twoje dane</h5>	</div>
			<%	User u = user_m.id_to_user(sessionFactory,s,user_id);%>
				<div id="username_data">
				<%
				out.println("Witaj "+ u.getName()+" !");
				out.println("<br>");
				out.println("Typ użytkownika: "+ u.getType()); 
				out.println("<br>");
				out.println("Jesteś z nami od: " + u.getAdd_date());
				%>
					
					<%
				out.println("<a href='logout.jsp'> Wyloguj się</a>");
			} else {  %>
			<h5>Logowanie uzytkownika</h5>	</div>

	<div id="username_label">User Name:</div>
	<div id="input">
		<label> <input name="username" type="text" class="input"
			id="username" required placeholder="enter your user name" />
		</label>
	</div>
	<div id="password_label">Password:</div>
	<div id="input02">
		<label> <input name="password" type="password" class="input"
			id="password" required placeholder="password" />
		</label>
	</div>
	<div id="loginbutton">
		<input id="login_submit" class="login" type="submit" value="zaloguj">
	</div>
	<div id="member">Not yet a Member?</div>
	<div id="register">
		<a href="addClient.jsp" class="register">Register Now</a>
	</div>
</div>
</form>

<% } 

 s.getTransaction().commit();
 s.close();
 %>